package com.sanhai.android.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import java.util.List;

/**
 * Created by mahuihuang on 15/3/19.
 */
public abstract class MultiViewAdapter<T> extends CommonAdapter<T> {
    private int position = 0;

    public MultiViewAdapter(Context context, List<T> datas) {
        super(context, datas, 0);
    }

    @Override
    public abstract int getViewTypeCount();

    public abstract int getItemViewLayoutId(T obj);

    public int getPosition() {
        return position;
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        if (this.datas == null || this.datas.size() <= position) {
            Log.e("MultiViewAdapter", "没有对应的数据:" + position);
            return null;
        }
        T obj = this.datas.get(position);
        int itemLayoutId = getItemViewLayoutId(obj);
        return ViewHolder.get(this.context, convertView, parent, itemLayoutId, position);
    }

}
